﻿<UserControl x:Class="BattleforgeAssault.CardView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:l="clr-namespace:BattleforgeAssault"
             mc:Ignorable="d"
             MouseEnter="OnMouseEnter"
             MouseLeftButtonDown="OnMouseDown"
             MouseRightButtonDown="OnRightMouseDown"
             >
    <UserControl.Resources>
        <l:IntToListConverter x:Key="listConverter" />
        
        <DropShadowEffect x:Key="shadowEffect" Opacity="0.5" />

        <ItemsPanelTemplate x:Key="rowPanelTemplate">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" />
        </ItemsPanelTemplate>

        <Style TargetType="ToolTip" x:Key="clearToolTipStyle">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToolTip">
                        <ContentPresenter 
                            Content="{TemplateBinding Content}" 
                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                            Cursor="{TemplateBinding Cursor}" 
                            Margin="{TemplateBinding Padding}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Name="cardImageStyle" TargetType="Image">
            <Setter Property="Image.Clip">
                <Setter.Value>
                    <RectangleGeometry Rect="0,0,107,150" RadiusX="4" RadiusY="4" />
                </Setter.Value>
            </Setter>
            <Setter Property="Width" Value="107" />
            <Setter Property="Height" Value="150" />
        </Style>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RenderTransform>
                <TransformGroup>
                    <RotateTransform x:Name="rotation" CenterX="53" CenterY="75" />
                    <TranslateTransform x:Name="translation" />
                    <ScaleTransform x:Name="scale" CenterX="53" CenterY="75" />
                </TransformGroup>
            </Grid.RenderTransform>

            <Border x:Name="cardFace" BorderBrush="Black" BorderThickness="2" CornerRadius="4" Background="Black" Width="111" Height="154" Effect="{StaticResource shadowEffect}">
                <Grid>
                    <Image x:Name="cardImage" Style="{StaticResource cardImageStyle}" Source="{Binding Front}">
                        <ToolTipService.ToolTip>
                            <ToolTip Style="{StaticResource clearToolTipStyle}" >
                                <Border BorderBrush="Black" CornerRadius="10" BorderThickness="2" Background="Black">
                                    <Grid>
                                        <Image x:Name="toolTipImage" Source="{Binding Front}" Width="214" Height="300">
                                            <Image.Clip>
                                                <RectangleGeometry Rect="0,0,214,300" RadiusX="8" RadiusY="8" />
                                            </Image.Clip>
                                        </Image>
                                        <Border Margin="4" Padding="2" Background="#9FFF" CornerRadius="4" HorizontalAlignment="Right" VerticalAlignment="Top">
                                            <StackPanel Width="150">
                                                <TextBlock Text="{Binding Title}" />
                                                <ItemsControl ItemsSource="{Binding Keywords}" />
                                                <TextBlock Text="{Binding Cost}" FontSize="16" Foreground="White" />
                                                <TextBlock Text="{Binding Loyalty}" FontSize="16" Foreground="Goldenrod" />
                                                <TextBlock Text="{Binding Power}" FontSize="16" Foreground="Crimson" />
                                                <TextBlock Text="{Binding HitPoints}" FontSize="16" Foreground="Gray" />
                                                <ItemsControl ItemsSource="{Binding Traits}" />
                                                <TextBlock Text="{Binding Text}" TextWrapping="Wrap" />
                                                <TextBlock Text="{Binding FlavorText}" FontStyle="Italic" TextWrapping="Wrap" />
                                                <TextBlock Text="{Binding Questing.Title, StringFormat=Questing: \{0\}}" />
                                            </StackPanel>
                                        </Border>
                                    </Grid>
                                </Border>
                            </ToolTip>
                        </ToolTipService.ToolTip>
                    </Image>
                    
                    <ItemsControl Height="24" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 8 8 0"
                        ItemsSource="{Binding DamageTaken, Converter={StaticResource listConverter}}" ItemsPanel="{StaticResource rowPanelTemplate}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Image Source="Resources/Skull.png" Width="24" Height="24" Effect="{StaticResource shadowEffect}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <ItemsControl Height="24" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 40 8 0"
                        ItemsSource="{Binding Tokens, Converter={StaticResource listConverter}}" ItemsPanel="{StaticResource rowPanelTemplate}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Image Source="Resources/Barrel.png" Width="24" Height="24" Effect="{StaticResource shadowEffect}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    
                </Grid>
            </Border>
            <Border x:Name="dimmer" CornerRadius="5" Background="Black" Opacity="0" IsHitTestVisible="False" />
        </Grid>
        <l:RadialPanel x:Name="menu" IsEquidistant="False" Opacity="0">
            <Button Content="Rotate" Click="OnRotateClick" />
            <Button x:Name="addDamageButton" Content="+D" Click="OnAddDamageClick" />
            <Button Content="Flip" Click="OnFlipClick" />
            <Button Content="+T" Click="OnAddTokenClick" />
            <Button Content="Move" Click="OnMoveClick" />
            <Button Content="-T" Click="OnRemoveTokenClick" />
            <Canvas IsHitTestVisible="False" />
            <Button x:Name="removeDamageButton" Content="-D" Click="OnRemoveDamageClick" />
        </l:RadialPanel>
    </Grid>
</UserControl>
